package com.fansl.allround.common.core.util;

import javax.imageio.ImageIO;
import java.awt.*;
import java.awt.geom.RoundRectangle2D;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

/**
 * @author fansl
 * @Description: logo制作工具
 * @date 2020/2/3 11:05
 */
public class LogoUtil {
    public static BufferedImage logoMatrix(BufferedImage matrixImage,String logo)throws IOException{
        //在二维码上画logo
        Graphics2D graphics2D = matrixImage.createGraphics();
        //画logo: String->bufferedImage(内存)
        BufferedImage logoImg = ImageIO.read(new File(logo));
        int height = matrixImage.getHeight();
        int width = matrixImage.getWidth();
        //纯logo图片
        graphics2D.drawImage(logoImg,width*2/5,height*2/5,width*1/5,height*1/5,null);

        //产生一个 画 白色圆角正方形的 画笔
        BasicStroke stroke = new BasicStroke(5,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
        //将画板-画笔 关联
        graphics2D.setStroke(stroke);
        //创建一个正方形
        RoundRectangle2D.Float round = new RoundRectangle2D.Float(width*2/5,height*2/5,width*1/5,height*1/5,
                BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
        graphics2D.setColor(Color.WHITE);
        graphics2D.draw(round);

        //灰色边框
        BasicStroke stroke2 = new BasicStroke(1,BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
        graphics2D.setStroke(stroke2);
        //创建一个正方形
        RoundRectangle2D.Float round2= new RoundRectangle2D.Float(width*2/5,height*2/5,width*1/5,height*1/5,
                BasicStroke.CAP_ROUND,BasicStroke.JOIN_ROUND);
        graphics2D.setColor(Color.GRAY);
        graphics2D.draw(round2);

        graphics2D.dispose();
        matrixImage.flush();
        return matrixImage;

    }
}
